package com.itestor.iptv.modules.common.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;

import com.itestor.iptv.global.actions.AbstractPagedQueryAction;
import com.itestor.iptv.global.bean.AbstractPagedQuery;
import com.itestor.iptv.modules.common.service.RegionManageService;
import com.itestor.iptv.modules.common.vo.RegionManageBean;
import com.itestor.iptv.modules.ne.bean.RobotManageQuery;
import com.itestor.iptv.modules.ne.bean.RobotManageTvWallQuery;
import com.itestor.iptv.modules.ne.service.RobotManageService;

public class IndexRobotTreeRobotManageAction extends AbstractPagedQueryAction{
private RobotManageService robotManageService;
private RegionManageService regionManageService;
	
	/**
     * Logger for this class.
     */
    private static final Logger logger = Logger
            .getLogger(IndexTvWallAction.class);

    @SuppressWarnings("unchecked")
    @Override   
    public AbstractPagedQuery doPagedQuery(ActionForm form,
            HttpServletRequest request, int pagerCount, int pagerOffset)
            throws Exception {
    	String id = request.getParameter("id");
        String name = request.getParameter("name");
        String region = request.getParameter("region");
        StringBuffer returnID = new StringBuffer(id);
        List<RegionManageBean> list = regionManageService.getRegionListByParentid(Integer.valueOf(id));
        for(RegionManageBean rmb : list){
        	returnID.append("," + rmb.getIdRegion());
        }
        RobotManageTvWallQuery robotManageQuery = new RobotManageTvWallQuery();
        robotManageQuery.setPagerPerPage(9);
        robotManageQuery.setPagerCount(pagerCount);
        robotManageQuery.setPagerOffset(pagerOffset);
        robotManageQuery.setRegion(region);
        robotManageQuery.setName(name);
        robotManageQuery.setId(returnID.toString());
        robotManageService.queryRobotManageRegionList(robotManageQuery);
    
        return robotManageQuery;
    }

	public void setRobotManageService(RobotManageService robotManageService) {
		this.robotManageService = robotManageService;
	}

	public void setRegionManageService(RegionManageService regionManageService) {
		this.regionManageService = regionManageService;
	}
}
